package com.djinfo.work.dao.impl;
import com.djinfo.work.common.dao.impl.BaseDaoImpl;
import com.djinfo.work.dao.RoleDao;
import com.djinfo.work.entity.TbSysRoles;
import org.springframework.stereotype.Repository;


import java.util.List;


/**
 * 角色
 */
@Repository("RoleDao")
public class RoleDaoImpl extends BaseDaoImpl implements RoleDao {
	@Override
	public void save(TbSysRoles tbSysRoles) {
		if (tbSysRoles.getPkRoleId() == null) {
			super.save(tbSysRoles);
		} else {
			super.update(tbSysRoles);
		}
	}

	@Override
	public void update(TbSysRoles tbSysRoles) {
		super.update(tbSysRoles);
	}

	@Override
	public void delete(TbSysRoles tbSysRoles) {
		super.delete(this.selectOne(tbSysRoles));
	}

	@Override
	public TbSysRoles selectOne(TbSysRoles tbSysRoles) {
		return (TbSysRoles)super.getByPrimaryKey(TbSysRoles.class, tbSysRoles.getPkRoleId());
	}

	@Override
	public List<TbSysRoles> page(TbSysRoles tbSysRoles, Integer pageNum, Integer pageSize) {
		String hql = " from TbSysRoles where 1=1 ";
		return (List<TbSysRoles>)super.pageQuery( hql,  pageNum,  pageSize);
	}

	@Override
	public Integer getAllRowCount() {
		String hql = "select count(*) from TbSysRoles ";
		return super.getUniqueObject(hql).hashCode();
	}

	@Override
	public List getMenuList(String roleId) {
		String hql = "select menuId from TbSysRoleMenu where roleId = ?";
		return super.getList(hql,roleId);
	}

	@Override
	public List getRoleList() {
		String hql = " from TbSysRoles where 1=1 ";
		return  (List<TbSysRoles>)super.getList(hql);
	}

	@Override
	public List getRoleList2(String uid) {
		String hql = " from TbSysRoles where userId=? ";
		return super.getList(hql,uid);
	}
}

